package model;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;

/**
 *
 * @author Merli András-Bertalan
 */
public class Attribute {

    private final SimpleStringProperty name;
    private final SimpleStringProperty type;
    private final SimpleBooleanProperty isUnique;
    private final SimpleBooleanProperty isPrimary;
    private SimpleStringProperty referenceTableName;
    private SimpleStringProperty referenceAttributeName;
    private Table referenceTable;
    private Attribute referenceAttribute;
    private final SimpleBooleanProperty isIndexed;

    public Attribute(String name, String type, boolean isUnique, boolean isPrimary) {
        this.name = new SimpleStringProperty(name);
        this.type = new SimpleStringProperty(type);
        this.isUnique = new SimpleBooleanProperty(isUnique);
        this.isPrimary = new SimpleBooleanProperty(isPrimary);
        this.referenceTableName = new SimpleStringProperty();
        this.referenceAttributeName = new SimpleStringProperty();
        this.isIndexed = new SimpleBooleanProperty(false);
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public void setType(String type) {
        this.type.set(type);
    }

    public void setIsUnique(boolean isUnique) {
        this.isUnique.set(isUnique);
    }

    public void setIsPrimary(boolean isPrimary) {
        this.isPrimary.set(isPrimary);
    }

    public void setReferenceTableName(String referenceTableName) {
        if (this.referenceTableName == null) {
            this.referenceTableName = new SimpleStringProperty();
        }
        this.referenceTableName.set(referenceTableName);
    }

    public void setIsIndexed(boolean isIndexed) {
        this.isIndexed.set(isIndexed);
    }

    public String getName() {
        return name.get();
    }

    public String getType() {
        return type.get();
    }

    public boolean getIsUnique() {
        return isUnique.get();
    }

    public boolean getIsPrimary() {
        return isPrimary.get();
    }

    public String getReferenceTableName() {
        return referenceTableName.get();
    }

    public boolean getIsIndexed() {
        return isIndexed.get();
    }

    public SimpleStringProperty getReferenceAttributeName() {
        return referenceAttributeName;
    }

    public void setReferenceAttributeName(String referenceAttributeName) {
        if (this.referenceAttributeName == null) {
            this.referenceAttributeName = new SimpleStringProperty();
        }
        this.referenceAttributeName.set(referenceAttributeName);
    }

    public Table getReferenceTable() {
        return referenceTable;
    }

    public void setReferenceTable(Table referenceTable) {
        this.referenceTable = referenceTable;
    }

    public Attribute getReferenceAttribute() {
        return referenceAttribute;
    }

    public void setReferenceAttribute(Attribute referenceAttribute) {
        this.referenceAttribute = referenceAttribute;
    }
}
